package com.itheima.mapper;

import com.itheima.entity.Article;
import com.itheima.entity.YddArticle;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface YddArticleMapper {

    /**
     * 通过cateId查询ydd_article中cate的个数
     *
     * @param cateid
     * @return {@link Integer}
     */
    @Select("select COUNT(*) from ydd_article where cateid = #{cateid}")
    Integer selectCountCateByCateId(Integer cateid);

    /**
     * 分页原始查询
     *
     * @param title
     * @param cateid
     * @param startTime
     * @param endTime
     * @return {@link List}<{@link YddArticle}>
     */
    //List<YddArticle> selectByPageInfo(String title, Integer cateid, Long startTime, Long endTime);
    /*<select id="selectByPageInfo" resultType="com.itheima.entity.YddArticle">
    select * from ydd_article
            <where>
                <if test="title != null and title != ''">
    and title like concat("%",#{title},"%")
                </if>
                <if test="cateid != null">
    and cateid = #{cateid}
                </if>
                <if test="startTime != null and endTime != null">
    and create_date between #{startTime} and #{endTime}
                </if>
            </where>
    </select>*/
    List<YddArticle> selectByPageInfo(String title, Integer cateid, Long startTime, Long endTime);


    /**
     * 添加文章
     *
     * @param article
     */
    void insert(Article article);

    /**
     * 回显
     *
     * @param id
     * @return {@link YddArticle}
     */
    @Select("select * from ydd_article where id = #{id}")
    YddArticle selectById(Long id);


    /**
     * 文章修改
     *
     * @param article
     */
    void update(Article article);


    /**
     * 删除文章
     *
     * @param id
     */
    @Delete("delete from ydd_article where id = #{id}")
    void delete(Long id);


    /**
     * 更新ydd_user_data 表
     *
     * @param type
     * @param userId
     * @param type
     */
    void insertUserAndData(Long articleId, Integer userId, int type);
}
